
{%- if vk_pixels -%}
  
  <!-- Top.Mail.Ru counter -->
  <script type="text/javascript">
    var _tmr = window._tmr || (window._tmr = []);
    {% for pixel in vk_pixels %}
    _tmr.push({id: "{{pixel}}", type: "pageView", start: (new Date()).getTime()});
    {% endfor %}

    {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'PageView'});
    {% endfor %}


    {%- if template == 'product_detail' -%}
      {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'ViewContent'});
      {% endfor %}
    {%- endif -%}


    {%- if template == 'search_detail' and search.keywords -%}
      {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'Search'});
      {% endfor %}
    {%- endif -%}


    {%- if controller == 'order' and action == 'success' -%}
      {% capture bigo_pixels_order_id %}bigo_pixels_{{order.id}}{% endcapture %}
      {% get_cache key={bigo_pixels_order_id} var_name=bigo_pixels_status%}
      {% if bigo_pixels_status ==0 %}
        {% for pixel in vk_pixels %}
          _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'Purchase',value: "{{ order.total_price }}" ,params:{product_id: '{{order.order_number}}'} });
        {% endfor %}
      {% endif %}
    {%- endif -%}



    {%- if template == 'order_contact_information' or template == 'orderonepage_index' -%}
      {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'InitiateCheckout'});
      {% endfor %}
    {%- endif -%}


    (function (d, w, id) {
      if (d.getElementById(id)) return;
      var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
      ts.src = "https://top-fwz1.mail.ru/js/code.js";
      var f = function () {var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s);};
      if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }
    })(document, window, "tmr-code");
  </script>
  {% for pixel in vk_pixels %}
  <noscript><div><img src="https://top-fwz1.mail.ru/counter?id={{pixel}};js=na" style="position:absolute;left:-9999px;" alt="Top.Mail.Ru" /></div></noscript>
  {% endfor %}

  <script type="text/javascript">
    function callback_vk_add_to_cart(ecdata) {
      {% for pixel in vk_pixels %}
        {%- if storeConfig.vkontakte_enable_ga == 1 -%}
          _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'AddToCart' ,value: ecdata['ec_data_price'] * ecdata['ec_data_quantity'],params:{product_id: ecdata['ec_data_id']} });
        {%- else -%}
          _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'AddToCart'});
        {%- endif -%}
      {% endfor %}

    }

    function callback_vk_generate_lead() {}

    function callback_vk_share_product(ec_data, platform) {}

    function callback_vk_begin_checkout() {}

    function callback_vk_login() {}

    function callback_vk_remove_from_cart(ecdata) {}

    function callback_vk_add_address_information() {}

    function callback_vk_add_shipping_information() {}

    function callback_vk_add_payment_information() {}


    function callback_vk_to_wishlist() {
      {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'AddToWishlist'});
      {% endfor %}
    }

    function callback_vk_sign_up() {
      {% for pixel in vk_pixels %}
        _tmr.push({ type: 'reachGoal', id: '{{pixel}}', goal: 'CompleteRegistration'});
      {% endfor %}
    }
  </script>
{%- endif -%}
